package com.zking.forward.index;

import com.zking.util.RedirectMsg;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/Logout")
public class Logout extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html");
        resp.setCharacterEncoding("UTF-8");
        resp.getWriter().write("<html><body><h1>Hello, Servlet!</h1></body></html>");

        // 注销session
        req.getSession().invalidate();

        req.setAttribute("msg", RedirectMsg.logoutSuccess);
        req.setAttribute("pageName", RedirectMsg.indexPageName);
        req.setAttribute("url", RedirectMsg.indexUrl);

        req.getRequestDispatcher("redirect.jsp").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
